package lablayer.model.MathComponents;

import lablayer.model.ComponentFactory;
import lablayer.model.Componentable;
import lablayer.model.LabData;

/**
 * @author Darkness
 */

class AccuracyAssessment implements MathComponent {
    private LabData result;

    private LabData data;

    private String componentName = "Точность оценки";

    private String componentId = "6";

    public AccuracyAssessment() {
        super();
        this.result = new LabData();
    }

    @Override
    public LabData getData() {
        return this.data;
    }

    @Override
    public void calculate() {
        Double value = 0.0;        
        Double[] dotStudent = null;
        if (this.data.getData()[0].length > 1) {            
            dotStudent = this.data.getData()[0][1];
        } else {
            throw new UnsupportedOperationException("AccuracyAssesment array length error");
        }
        
        Componentable amsError = ComponentFactory.createComponent(
                MathComponentFactory.createStandardAMSError());
        amsError.setData(this.data);
        amsError.calculate();
        if (dotStudent.length != 0) {
            value = amsError.getResult().getData()[0][0][0] * dotStudent[0];
        }
        this.result = new LabData(LabData.parseString(value.toString()));
    }

    @Override
    public void setData(LabData data) {
        if (data != null) {
            this.data = data;
        } else {
            throw new NullPointerException();
        }
    }

    @Override
    public String getComponentId() {
        return this.componentId;
    }

    @Override
    public String getComponentName() {
        return this.componentName;
    }

    @Override
    public LabData getResult() {
        return this.result;
    }

	@Override
	public void setParameter(String params, String values) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public LabData getInitData() {
		throw new UnsupportedOperationException("Not supported yet.");
	}

}
